package com.cysion.study.ui.personal

import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.content.res.ResourcesCompat
import android.view.View
import com.cysion.study.ktbox.base.BaseActivity
import com.cysion.study.ktbox.base.BaseFragmentAdapter
import com.cysion.study.ktbox.utils.CLog
import com.cysion.study.ktbox.utils.darkTextTheme
import com.cysion.other.color
import com.cysion.targetfun._addOnPageChangeListener
import com.cysion.study.uibox.bar.TopBar
import com.cysion.study.uibox.dialog.AlertSearch
import com.cysion.study.R
import com.cysion.study.ui.fragment.ActivityNoFragment
import kotlinx.android.synthetic.main.activity_activity_manage.*
import java.util.*

/**
 * 活动管理【旧页面，暂未使用  活动管理已改版】
 * Created by chu on 2019-06-30.
 */
class ActivityManageActivity:BaseActivity(), View.OnClickListener {
    private lateinit var mFragments: MutableList<Fragment>
    private lateinit var mTitles: MutableList<String>
    override fun getLayoutId(): Int {
        return R.layout.activity_activity_manage
    }

    override fun initView() {
        topbar
        darkTextTheme(color(R.color.main_cl))
        topbar.apply {
            initElements(TopBar.ELEMENT.HIDE,TopBar.ELEMENT.TEXT,TopBar.ELEMENT.TEXT)
            setTitle("活动管理")
            setTexts("搜索", TopBar.Pos.RIGHT)
            setOnTopBarClickListener { obj, pos ->
                if (pos == TopBar.Pos.RIGHT) {
                    searchF()
                }
            }

        }

        vp_content.offscreenPageLimit = 3
        tab1.setOnClickListener(this)
        tab2.setOnClickListener(this)
        tab3.setOnClickListener(this)
        intab1()

        mFragments = getFragments()
        mTitles = getTitles()
        vp_content.adapter = BaseFragmentAdapter(supportFragmentManager, mFragments, mTitles)
        vp_content._addOnPageChangeListener {
            _onPageSelected {
                when (it) {
                    0 -> {
                        intab1()//未开始
                        vp_content.currentItem = it
                    }
                    1 -> {
                        vp_content.currentItem = it
                        intab2()//进行中
                    }
                    2 -> {
                        vp_content.currentItem = it
                        intab3()//已结束
                    }
                }
            }
        }
    }

    private fun searchF() {
        AlertSearch.search(this,""){ confirm: Int, start: String, end: String ->
            CLog.i("@@@时期"+start+end)
//                        getDataList(curPage,start,end)
        }

    }

    var type = "0"

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.tab1 -> {//
                intab1()
                type = "0"
                vp_content.currentItem = 0
            }
            R.id.tab2 -> {//
                type = "1"
                intab2()
                vp_content.currentItem = 1
            }
            R.id.tab3 -> {//
                type = "1"
                intab3()
                vp_content.currentItem = 2
            }
        }

    }


    private fun getFragments(): MutableList<Fragment> {
        val fragmentArrayList = ArrayList<Fragment>()
        val c1 = ActivityNoFragment()
        val c2 = ActivityNoFragment()
        val c3 = ActivityNoFragment()

        val b1 = Bundle()
        val b2 = Bundle()
        val b3 = Bundle()

        b1.putString("type", "1")
        c1.arguments = b1
        fragmentArrayList.add(c1)//本周

        b2.putString("type", "2")
        c2.arguments = b2
        fragmentArrayList.add(c2)//本周

        b3.putString("type", "3")
        c3.arguments = b3
        fragmentArrayList.add(c3)//本周

        return fragmentArrayList
    }


    private fun getTitles(): MutableList<String> {
        val strings = ArrayList<String>()
        strings.add("未考核")
        strings.add("已考核")
        return strings
    }

    private fun intab1() {
        tab1.background = ResourcesCompat.getDrawable(getResources(), R.drawable.tab1, null)
        tab2.background = ResourcesCompat.getDrawable(getResources(), R.drawable.white_bg, null)
        tab3.background = ResourcesCompat.getDrawable(getResources(), R.drawable.white_bg, null)
        tab1.setTextColor(resources.getColor(R.color.white))
        tab2.setTextColor(resources.getColor(R.color.main_cl))
        tab3.setTextColor(resources.getColor(R.color.main_cl))
    }

    private fun intab2() {
        tab1.background = ResourcesCompat.getDrawable(getResources(), R.drawable.white_bg, null)
        tab2.background = ResourcesCompat.getDrawable(getResources(), R.drawable.tab1, null)
        tab3.background = ResourcesCompat.getDrawable(getResources(), R.drawable.white_bg, null)
        tab1.setTextColor(resources.getColor(R.color.main_cl))
        tab2.setTextColor(resources.getColor(R.color.white))
        tab3.setTextColor(resources.getColor(R.color.main_cl))
    }
    private fun intab3() {
        tab1.background = ResourcesCompat.getDrawable(getResources(), R.drawable.white_bg, null)
        tab2.background = ResourcesCompat.getDrawable(getResources(), R.drawable.white_bg, null)
        tab3.background = ResourcesCompat.getDrawable(getResources(), R.drawable.tab1, null)
        tab1.setTextColor(resources.getColor(R.color.main_cl))
        tab2.setTextColor(resources.getColor(R.color.main_cl))
        tab3.setTextColor(resources.getColor(R.color.white))
    }
    override fun closeMvp() {
    }
}